package main

import (
	"context"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	v1 "rpc-demo/proto/v1/pb"
	"time"
)

var addr = "localhost:50051"
var name = "world"

func main() {
	conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("connection to server error: %v", err)
	}
	defer conn.Close()

	client := v1.NewGreeterClient(conn)
	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	helloResponse, err := client.SayHello(ctx, &v1.HelloRequest{UserId: 10})
	if err != nil {
		log.Fatalf("call rpc server error : %v", err)
	}
	log.Printf("get response %v", helloResponse)
}
